package com.xtayfjpk.zookeeper.test.master_workers.curator.listener;

import java.io.IOException;

import org.apache.curator.framework.api.UnhandledErrorListener;
import org.apache.log4j.Logger;

import com.xtayfjpk.zookeeper.test.master_workers.curator.CuratorMaster;

public class ErrorsListener implements UnhandledErrorListener {
private static final Logger LOGGER = Logger.getLogger(ErrorsListener.class);
	
	private CuratorMaster master;
	
	public ErrorsListener(CuratorMaster curatorMaster) {
		this.master = curatorMaster;
	}
	@Override
	public void unhandledError(String message, Throwable e) {
		 LOGGER.error("Unrecoverable error: " + message, e);
         try {
             master.close();
         } catch (IOException ioe) {
             LOGGER.warn( "Exception when closing.", ioe );
         }
	}

}
